﻿// ==================================================
// Copyright © 2016 杭州伯庸科技 版权所有
//
// 文 件 名：OpenBookmark
// 功能描述：
//
// 创建标识：Yu.Liang(俞 亮) 2018/4/5 10:18:32
//
// 修改标识：
// 修改描述：
// ==================================================

using Shine.Framework;
using SuperMap.Realspace;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Shine.Viewer
{
    public class OpenBookmark : BaseCommand
    {
        IApplication m_Application = null;
        ViewSpotListUserForm m_usf = null;
        string bookmarkfile = string.Empty; 

        public OpenBookmark()
        {
            base.m_caption = "加载视点";
            base.m_name = "OpenBookmark";
            base.m_toolTip = "加载视点";
            base.m_message = "加载视点";
            base.m_category = "Viewer";
        }

        public override void OnCreate(object hook)
        {
            if (m_Application == null)
            {
                m_Application = hook as IApplication;
                if (m_usf == null)
                {
                    m_usf = (m_Application as IFramework).DockManager.GetControlFromDockPanel("视点管理") as ViewSpotListUserForm;
                }
            }
        }

        public override void OnClick()
        {
            if (m_usf == null)
                return;

            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Multiselect = false;
            dlg.Filter = "视点管理文件(*.xml) | *.xml";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                bookmarkfile = dlg.FileName;
                if (File.Exists(bookmarkfile))
                {
                    m_usf.LoadBookmarks(bookmarkfile);
                }
            }
            else
            {
                m_usf.LoadBookmarks(null);
            }
        }

        public override int Bitmap
        {
            get
            {
                string imgFile = Application.StartupPath + "\\Images\\" + GetType().Name + ".png";

                if (System.IO.File.Exists(imgFile) == false) return 0;

                return new Bitmap(Image.FromFile(imgFile)).GetHbitmap().ToInt32();
            }
        }

        public override bool Enabled
        {
            get { return (m_Application as IFramework).IsSceneCtlActive;}
        }
    }
}
